<?php

if(STAINLESS != 1){
	require_once('../config.php');
	redirect("$home_url/admin/login/");
}

if(isset($_GET['id'])){
	$id = trim($_GET['id']);
	if(!validate($id,DATA_NUMERIC)){
		$notice = 'delete_error';
	}else{
		$db = new models($host,$user,$pass,$db_name);
		$db->select("id,photo");
		$db->where("id='$id'");
		$product = $db->get_data("products");
		
		if($product){
			$db->delete("products");
			if($product[0]['photo']){
				$file_photo = HOME_DIR . "/images/photos/" . $product[0]['photo'];
				if(!unlink($file_photo)){
					$notice="delete_logo_error";
				}
			}
			$notice="delete_success";
		}else{
			$notice="delete_error";
		}
	}
	redirect("$home_url/admin/products/?notice=$notice");
}